package ru.hashcode.hashdroid;

import java.util.List;

import ru.hashcode.hashdroid.proxy.HashCode;
import ru.hashcode.hashdroid.proxy.Question;
import ru.hashcode.hashdroid.proxy.Sort;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;

public class QuestionListActivity extends ListActivity {
	
	List<Question> list;

	public final static String extraName = "TAB";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ResourcesHandler.setResources(this);
		
		//long t1 = System.nanoTime();
		list = HashCode.getInstance().getData(getIntent().getIntExtra(extraName, 0), Sort.Hottest, 0);
		setListAdapter(new QuestionListAdapter(this, list));
		//long t2 = System.nanoTime();
		//Log.v("checktime", "" + (t2 - t1) / 1000);
	}
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		Intent intent = new Intent(this, QuestionViewActivity.class);
		QuestionViewActivity.setQuestion(list.get(position));
		startActivityForResult(intent, RESULT_OK);
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		setTitle(getText(R.string.app_name));
	}
}
